<?php
	/*
	 * @METHOD: POST or GET
	 * @PARAM:	txt - text to be checked
	 * @PARAM:	lan	- languange text is written in
	 * @PARAM:	dgt	- Ignore digits in text (0:no, 1:yes)
	 * @PARAM:	cap	- Ignore words that are completely capitalized (0:no, 1:yes)
	 *
	 * @AUTHOR: Bade I. (c) 2009
	 */
	
	// VARIABLES AND DEFUALTS
	$url="https://www.google.com/tbproxy/spell?lang=";
	$lang = "en";
	$text = "";
	$idgt = 0;
	$icap = 0;
	$debug = false;
	
	//Assign parameters
	$text = isset($_GET['txt'])?trim($_GET['txt']):$text;
	$text = isset($_POST['txt'])?trim($_POST['txt']):$text;
	$lang = (isset($_GET['lan']) && strlen(trim($_GET['lan'])) == 2)?strtolower(trim($_GET['lan'])):$lang;
	$lang = (isset($_POST['lan']) && strlen(trim($_POST['lan'])) == 2)?strtolower(trim($_POST['lan'])):$lang;
	$idgt = (isset($_GET['dgt']) && intval(trim($_GET['dgt'])) == 1)?1:0;
	$idgt = (isset($_POST['dgt']) && intval(trim($_POST['dgt'])) == 1)?1:$idgt;
	$icap = (isset($_GET['cap']) && intval(trim($_GET['cap'])) == 1)?1:0;
	$icap = (isset($_POST['cap']) && intval(trim($_POST['cap'])) == 1)?1:$icap;
	if($debug) { 
		echo "Text: $text<br />";
		echo "Language: $lang<br />";
		echo "Ignore Digits: $idgt<br />";
		echo "Ignore All Caps: $icap<br />";
	}
	
	header("Content-Type: text/xml; charset=utf-8");
	$url .= $lang;
	 
	$body = '<?xml version="1.0" encoding="utf-8" ?>';
	$body .= '<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="'.$idgt.'" ignoreallcaps="'.$icap.'">';
	$body .= '<text>' . $text . '</text>';
	$body .= '</spellrequest>';
	 
	$ch = curl_init();
	curl_setopt ($ch, CURLOPT_URL, $url);
	curl_setopt ($ch, CURLOPT_POST, 1);
	curl_setopt ($ch, CURLOPT_POSTFIELDS, $body);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	$contents = curl_exec ($ch);
	curl_close ($ch);
	 
	echo $contents;
?>